package com.hdu.seckilldemo.utils;

import org.apache.commons.codec.digest.DigestUtils;

public class MD5Util {
    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }
    private static final String salt="1a2b3c4d";

    //模拟前端传来的密码
    public static String inputPassFrontPass(String inputpass){
        String str = ""+salt.charAt(0)+salt.charAt(2)+inputpass+salt.charAt(5)+salt.charAt(4);
        return md5(str);
    }
    public static String frontPassToDBPass(String formPass,String salt){
        String str = salt.charAt(0)+salt.charAt(2)+formPass+salt.charAt(5)+salt.charAt(4);
        return md5(str);
    }
    public static String inputPassToDBPass(String inputPass, String salt){
        String frontPass = inputPassFrontPass(inputPass);
        return frontPassToDBPass(frontPass,salt); //二次加密的存到数据库中的密码

    }

    public static void main(String[] args) {
        System.out.println(inputPassFrontPass("123456"));
        //d3b1294a61a07da9b49b6e22b2cbd7f9
        System.out.println(frontPassToDBPass("d3b1294a61a07da9b49b6e22b2cbd7f9",salt));
        //6e0a7fe692684372437c9e508508990d
        System.out.println(inputPassToDBPass("123456",salt));
    }

}
